<?php
namespace Common\Org\YzPay;

class YzPay {
	protected $config;
	public function __construct($paytype, $config) {
		if ($paytype == "Alipay") {
			$this->PayClass = new \Common\Org\YzPay\Alipay\AopClient($config);
		} else if ($paytype == "WxPay") {
			$this->PayClass = new \Common\Org\YzPay\WxPay\Wxpay($config);
		}
	}

	//生成支付二维码
	public function QRCode($params) {
		return $this->PayClass->QRCode($params);
	}
	//支付成功验证回调
	public function verifyNotify() {
		return $this->PayClass->verifyNotify();
	}
	//验证银行卡
	public function checkBank($params) {
		$req = array();
		//验证银行卡信息
		$config = array(
			'app_id' => '1441071499740581',
			'md5_key' => 'DK96gnOB7EmVDDaHgLTLEZqVgP0H0nML',
			'des_key' => 'Z5CbXbEaJA6CYRSDS5Ddsab6',
			'trans_url' => 'http://posp.ipaynow.cn:20320',
			'query_url' => 'http://www.codecamp.com/',
			'check_funcode' => 'ID02',
		);
		$req["bankCardNum"] = $params['bankCardNum']; //银行账户
		$req["certiType"] = "01"; //证件类型
		$req["funcode"] = "ID02";
		$req["idCard"] = $params['idCard']; //身份证号
		$req["idCardName"] = $params['idCardName']; //姓名
		$req["mhtOrderNo"] = date("YmdHis");
		//$req["mobile"] = $params['mobile']; //手机号
		$Services = new \Common\Org\AgentPay\Services($config);
		$req_content = $Services->buildAndSendCheckReq($req);
		parse_str($req_content, $parr);
		if ($parr['responseCode']) {
			return $parr;
		} else {
			return array('responseCode' => 'diy_002', 'responseMsg' => $req_content);
		}

	}
//代付
	public function angentPay($param) {
		$config = array(
			'app_id' => '1459846530407363',
			'md5_key' => 'oAKsBv38CcLdnIn5N733oiY81erfotAC',
			'des_key' => 'e2KSP6awXjkbfm8eR3iE2BmW',
			'trans_url' => 'https://dby.ipaynow.cn/agentpay/agentPay',
			'query_url' => 'http://yzpay.boxphp.me//',
			'check_funcode' => 'AP04',
		);
		$req = array();
		$req["agentPayMemo"] = $param['agentPayMemo'];
		$req["funcode"] = "AP04";
		$req["mhtOrderNo"] = date("YmdHis");
		$req["mhtReqTime"] = date("YmdHis");
		$req["payeeAccType"] = "02";
		$req["payeeName"] = $param['payeeName'];
		$req["payeeCardNo"] = $param['payeeCardNo'];
		$req["mhtOrderAmt"] = $param['money'];
		$Services = new \Common\Org\AgentPay\AgentPayServices($config);
		$req_content = $Services->buildAndSendCheckReq($req);
		parse_str($req_content, $parr);
		if ($parr['responseCode']) {
			return $parr;
		} else {
			return array('responseCode' => 'diy_002', 'responseMsg' => $req_content);
		}
	}

}
